---
description: Couchbase mobile database indexes and indexing concepts
related_content:
  - name: Databases
    url: /databases
  - name: Documents
    url: /documents
  - name: Indexing
    url: /indexing
---

# Indexes

## Introduction

Before we begin querying documents, let's briefly mention the importance of
having an appropriate and balanced approach to indexes.

Creating indexes can speed up the performance of queries. A query will typically
return results more quickly if it can take advantage of an existing database
index to search, narrowing down the set of documents to be examined.

:::note Constraints

Couchbase Lite does not currently support partial value indexes; indexes with
non-property expressions. You should only index with properties that you plan to
use in the query.

:::

## Creating a new index

You can use SQL++ or QueryBuilder syntaxes to create an index.

[Example 2](#) creates a new index for the `type` and `name` properties, shown
in this data model:

<CodeExample id={1} title="Data Model">

```json
{
  "_id": "hotel123",
  "type": "hotel",
  "name": "The Michigander",
  "overview": "Ideally situated for exploration of the Motor City and the wider state of Michigan. Tripadvisor rated the hotel ...",
  "state": "Michigan"
}
```

</CodeExample>

### SQL++

The code to create the index will look something like this:

<CodeExample id={2} title="Create index with SQL++">

```dart
final config = ValueIndexConfiguration(['type', 'name']);
await database.createIndex('TypeNameIndex', config);
```

</CodeExample>

### QueryBuilder

The code to create the index will look something like this:

<CodeExample id={3} title="Create index QueryBuilder">

```dart
final typeExpression = Expression.property('type');
final nameExpression = Expression.property('name');
final valueIndexItems = {
	ValueIndexItem.expression(typeExpression),
	ValueIndexItem.expression(nameExpression),
};
final index = IndexBuilder.valueIndex(valueIndexItems);
await database.createIndex('TypeNameIndex', index);
```

</CodeExample>

## Summary

When planning the indexes you need for your database, remember that while
indexes make queries faster, they may also:

- Make writes slightly slower, because each index must be updated whenever a
  document is updated.
- Make your Couchbase Lite database slightly larger.

So too many indexes may hurt performance. Optimal performance depends on
designing and creating the _right_ indexes to go along with your queries.
